package test;

import dao.GradeMapper;
import dao.StudentMapper;
import dao.SubjectMapper;
import entity.Grade;
import entity.Subject;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import util.MybatisUtil;

import java.io.IOException;
import java.io.Reader;
import java.util.List;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class SubjectTest {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int choice = 0;
        while (true){
            SqlSession session = MybatisUtil.get();
            SubjectMapper mapper = session.getMapper(SubjectMapper.class);
            System.out.println("1.增加课程 2修改 3删除课程 4查询全部 5分页 6.id查询  0退出");
            choice=in.nextInt();
            switch (choice){
                case 1:
                    System.out.println("请输入课程名称");
                    String name=in.next();
                    System.out.println("请输入课时");
                    int ks=in.nextInt();
                    System.out.println("请输入年级编号");
                    int nj=in.nextInt();
                    Subject subject=new Subject(name,ks,nj);
                    int a=mapper.add(subject);
                    System.out.println(a);
                    MybatisUtil.close(session);

                    break;
                case 2:
                    System.out.println("请输入要修改课程编号");
                    int id=in.nextInt();
                    System.out.println("请输入课程名称");
                    String name2=in.next();
                    System.out.println("请输入课时");
                    int ks2=in.nextInt();
                    System.out.println("请输入年级编号");
                    int nj2=in.nextInt();
                    Subject subject2=new Subject(id,name2,ks2,nj2);
                    int a2=mapper.update(subject2);
                    System.out.println(a2);
                    MybatisUtil.close(session);
                    break;
                case 3:
                    System.out.println("请输入要删除课程编号");
                    int id3=in.nextInt();
                    int a3=mapper.del(id3);
                    System.out.println(a3);
                    MybatisUtil.close(session);
                    break;
                case 4:
                    List<Subject> all = mapper.findALL();
                    all.forEach(System.out::println);
                    //session.commit();
                    session.close();
                    break;
                case 5:
                    List<Subject> list = mapper.fenye(2,5);
                    list.forEach(System.out::println);
                    //session.commit();
                    session.close();
                    break;
                case 6:
                    Subject subject6=mapper.get(3);
                    System.out.println(subject6);
                    System.out.println("年纪名："+subject6.getGname());
                    //session.commit();
                    session.close();
                    break;
                case 0:

                    return;

            }

        }


    }
}
